import type { ApiType } from '.';
import { request } from '../request';

/* 文章主页列表 */
export function mainArticleList(
  params: {
    categoryId?: string;
    tagId?: string;
    order: string;
  } & Api.PageParam,
) {
  return request<
    Api.PageVO<
      {
        category: Api.Category;
        topic: { id: string; name: string };
        tagInfoList: Api.TagInfo[];
        userInfo: Api.ArticleUserVO;
        relativeTime: Api.UserInfo;
        isStar: boolean;
      } & Api.Article
    >
  >({
    url: '/main/article-list',
    method: 'post',
    data: params,
  });
}

/* 文章关注页面列表 */
export function mainArticleFollowList(
  params: {
    order: 'edit_time' | 'read_num' | string;
  } & Api.PageParam,
) {
  return request<
    Api.PageVO<
      {
        category: Api.Category;
        topic: { id: string; name: string };
        tagInfoList: Api.TagInfo[];
        userInfo: Api.ArticleUserVO;
        relativeTime: Api.UserInfo;
        isStar: boolean;
      } & Api.Article
    >
  >({
    url: '/main/article-follow-list',
    method: 'post',
    data: params,
  });
}
/* 文章搜索 */
export function mainSearchArticle(
  params: {
    text: string;
    order: string;
  } & Api.PageParam,
) {
  return request<ApiType<typeof mainArticleList>['Return']>({
    url: '/main/search-article',
    method: 'post',
    data: params,
  });
}

/* 分类信息列表 */
export function mainCategoryList() {
  return request<Array<{ num: number } & Api.Category>>({
    url: '/main/category-list',
    method: 'get',
  });
}

/* 标签信息列表 */
export function mainTagList() {
  return request<Array<Api.TagInfo>>({
    url: '/main/tag-list',
    method: 'get',
  });
}

/* 标签信息分页查询列表 */
export function mainTagQryList(params: { text: string } & Api.PageParam) {
  return request<Api.PageVO<{ followFlag: boolean } & Api.TagInfo>>({
    url: '/main/tag-qry-list',
    method: 'post',
    data: params,
  });
}

/* 标签信息根据ID查询列表 */
export function mainTagGet(params: { id: string }) {
  return request<{ followFlag: boolean } & Api.TagInfo>({
    url: '/main/tag-get',
    method: 'post',
    data: params,
  });
}

/* 话题信息分页查询列表 */
export function mainTopicQryList(params: { text: string } & Api.PageParam) {
  return request<Api.PageVO<{ followFlag: boolean } & Api.TopicInfo>>({
    url: '/main/topic-qry-list',
    method: 'post',
    data: params,
  });
}

/* 话题信息根据ID查询列表 */
export function mainTopicGet(params: { id: string }) {
  return request<{ followFlag: boolean } & Api.TopicInfo>({
    url: '/main/topic-get',
    method: 'post',
    data: params,
  });
}
/* 热榜文章信息 */
export function mainHotArticle() {
  return request<
    Array<{
      id: string;
      content: string;
      readNum: number;
    }>
  >({
    url: '/main/hot-article',
    method: 'get',
  });
}
/* 热榜话题信息 */
export function mainHotTopic() {
  return request<ApiType<typeof mainHotArticle>['Return']>({
    url: '/main/hot-topic',
    method: 'get',
  });
}

/* 热榜标签信息 */
export function mainHotTag() {
  return request<ApiType<typeof mainHotArticle>['Return']>({
    url: '/main/hot-tag',
    method: 'get',
  });
}

/* 热榜用户信息 */
export function mainHotUser() {
  return request<
    Array<{
      id: string;
      username: string;
      summary: string;
      avatar: string;
      readNum: number;
      followFlag: boolean;
    }>
  >({
    url: '/main/hot-user',
    method: 'get',
  });
}
